package hivMultiCompartment;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

import uchicago.src.sim.util.SimUtilities;

public abstract class OrganGeneral {

	public Model theModel;
	
	//agents and ports on the grid
	public ArrayList<Cell> cellList;
	public ArrayList<Virus> virusList;
	// input queues
	public ArrayList<Cell> inputCellsList;
	public ArrayList<Virus> inputVirusList;
	//temp proliferation queue
	public ArrayList<Cell> prolifCellList;
	public ArrayList<Virus> prolifVirusList;
	//recruitment queue
	public ArrayList<Cell> recruitCellList; // cells in this list will be processed first, and will be cleared if unable to add to grid
	
	public OrganGeneral (Model aModel) {
		theModel = aModel;
		
		cellList = new ArrayList<Cell> ();
		virusList = new ArrayList<Virus> ();
		
		inputCellsList = new ArrayList<Cell> ();
		inputVirusList = new ArrayList<Virus> ();
		
		prolifCellList = new ArrayList<Cell> ();
		prolifVirusList = new ArrayList<Virus> ();

		recruitCellList = new ArrayList<Cell> ();
	}
	
	public abstract void step();
	
	public void shuffleAgents() {
		SimUtilities.shuffle( cellList, uchicago.src.sim.util.Random.uniform );
		SimUtilities.shuffle( virusList, uchicago.src.sim.util.Random.uniform );
	}
	
	/**
	 * remove dead agents from list
	 */
	public void removeDeadAgents(){
		Iterator<Cell> cIter = cellList.iterator();
		while (cIter.hasNext()) {
			Cell c = cIter.next();
			if(!c.isAlive()) {
				cIter.remove();
			}
		}
		Iterator<Virus> vIter = virusList.iterator();
		while (vIter.hasNext()) {
			Virus v = vIter.next();
			if(!v.isAlive()) {
				vIter.remove();
			}
		}
	}
	
	
}
